﻿Imports Microsoft.WindowsAPICodePack.Taskbar
Imports System.Resources
Imports VB = Microsoft.VisualBasic
Imports System.IO
Imports TwitterVB2
Imports System.Xml

Public Class frmMain
    Private WithEvents ApacheStart, ApacheStop, MySQLStart, MySQLStop As ThumbnailToolbarButton
    Dim sc As New Service

    Public Const PUB_KEY As String = "RSA512<RSAKeyValue><Modulus>5SvApDf37QiXTh9pdet6fPzcte+RCodev0dhzLkfuPVlINZZryhfVvkmbCXWStkYc+fnP8jkNJd5SeqEYKSkxQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"

    Public MyActiveLock As ActiveLock3_6NET._IActiveLock
    Public WithEvents ActiveLockEventSink As ActiveLock3_6NET.ActiveLockEventNotifier
    Public Const LICENSE_ROOT As String = "AIO Suite"
    ' Trial information string
    Public strMsg, strRemainingTrialDays, strRemainingTrialRuns, strTrialLength As String
    Public strUsedDays, strExpirationDate, strRegisteredUser, strRegisteredLevel As String
    Public strLicenseClass, strMaxCount, strLicenseFileType, strLicenseType, strUsedLockType As String
    Public remainingDays, remainingRuns As Integer
    Public totalDays, totalRuns As Integer
    ' Trial mode variables
    Dim noTrialThisTime As Boolean 'needed for registration while form was loaded via trial
    Dim expireTrialLicense As Boolean
    Dim strKeyStorePath As String
    Dim strAutoRegisterKeyPath As String


    Public Reg_Status As String
    Public Used_Days As String
    Public User As String
    Public RegisteredLevel As String
    Public LicenseType As String
    Public Expiration As String '   'Var for data processing



    'Twitter Vars
    Public username As String
    Public password As String
    Public Const ConsumerKey = "w0suIX0FsQ4Nfv85kNjrIg"
    Public Const ConsumerKeySecret = "BvlJ6DNtnBHi1vTjWpf1Oab5oAwZdOb4PG1KX33dzs"
    Private OAuthToken As String
    Private OAuthTokenSecret As String
    Public T_LDetails As Boolean = False
    Private m_colFriends As Collection
    Private m_colFollwer As Collection

    Private Sub StartApache_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles StartApache.Click
        Try
            If isAdministrator() = True Then
                sc.StartService("Apache2.2")
            Else
                Throw New ApplicationException("Start this program as admin")
            End If
            MsgBox(My.Computer.Clock.TickCount)
            If ServiceController1.Status = ServiceProcess.ServiceControllerStatus.Running Then
                MsgBox("Service is running")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub StopApache_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles StopApache.Click
        Try
            ServiceController1.ServiceName = "Apache2.2"
            If isAdministrator() = True Then
                If ServiceController1.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    ServiceController1.Stop()
                End If
            Else
                Throw New ApplicationException("Start this program as admin")
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub StartMySQL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles StartMySQL.Click
        Try
            ServiceController1.ServiceName = "MySQL"
            If isAdministrator() = True Then
                If ServiceController1.Status = ServiceProcess.ServiceControllerStatus.Stopped Then
                    ServiceController1.Start()
                End If
            Else
                Throw New ApplicationException("Start this program as admin")
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub StopMySQL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles StopMySQL.Click
        Try
            ServiceController1.ServiceName = "MySQL"
            If isAdministrator() = True Then
                If ServiceController1.Status = ServiceProcess.ServiceControllerStatus.Running Then
                    ServiceController1.Stop()
                End If
            Else
                Throw New ApplicationException("Start this program as admin")
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Public Function isAdministrator() As Boolean
        ' Check if the user is authenticated before continuing.
        If My.User.IsAuthenticated Then
            ' If the user is in the administrators group.
            If My.User.IsInRole("Administrators") Then
                Return True
            End If
        Else
            Return False
        End If

    End Function

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Activelock
        Dim boolAutoRegisterKeyPath As Boolean
        'Dim Msg As String

        ' Set the path to the license file (LIC) and ALL file (if it exists)
        'Dim Ret As Long
        Dim AppfilePath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)


        'The second line is used when unmanaged Activelock3NET.dll is used
        Dim MyAL As New ActiveLock3_6NET.Globals
        'Dim MyAL As New ActiveLock3.Globals

        ' Set a new instance of the Activelock object
        MyActiveLock = MyAL.NewInstance()

        With MyActiveLock

            ' Set the software/application name
            .SoftwareName = LICENSE_ROOT
            ' Set the software/application version number
            ' Note: Do not use (App.Major & "." & App.Minor & "." & App.Revision)
            ' since the license will fail with version incremented via exe rebuilds
            ' THE FOLLOWING IS A SAMPLE USAGE
            ' WARNING *** WARNING *** DO NOT USE App.Major & "." & App.Minor & "." & App.Revision
            '.SoftwareVersion = "1.3.2"   
            .SoftwareVersion = "1.0" ' WARNING *** WARNING *** DO NOT USE App.Major & "." & App.Minor & "." & App.Revision

            ' Set the software/application password
            ' This should be set to protect yourself against ResetTrial abuse
            ' The password is also used by the short keys
            ' Regular licensing does not use this password, but you should still use a password
            ' WARNING: You can not ignore this property. You *must* set a password.
            .SoftwarePassword = "fgh789"

            ' Set whether the software/application will use a short key or RSA method
            ' alsRSA covers RSA native classes approach.
            ' RSA classes in .NET allows you to pick from several cipher strengths
            ' alsShortKeyMD5 is for short key protection only
            ' WARNING: Short key licenses use the lockFingerprint by default
            '.LicenseKeyType = ActiveLock3_6NET.IActiveLock.ALLicenseKeyTypes.alsShortKeyMD5
            .LicenseKeyType = ActiveLock3_6NET.IActiveLock.ALLicenseKeyTypes.alsRSA

            ' Set the Trial Feature properties
            ' If you don't want to use the trial feature in your app, set the TrialType
            ' property to trialNone.

            ' Set the trial type property
            ' this is either trialDays, or trialRuns or trialNone.
            '.TrialType = ActiveLock3_6NET.IActiveLock.ALTrialTypes.trialRuns
            .TrialType = ActiveLock3_6NET.IActiveLock.ALTrialTypes.trialDays

            ' Set the Trial Length property.
            ' This number represents the number of days or the number of runs (whichever is applicable).
            .TrialLength = 30
            If .TrialType <> ActiveLock3_6NET.IActiveLock.ALTrialTypes.trialNone And .TrialLength = 0 Then
                ' In such cases Activelock automatically generates errors -11001100 or -11001101
                ' to indicate that you're using the trial feature but, trial length was not specified
            End If

            ' Comment the following statement to use a certain trial data hiding technique
            ' Use OR to combine one or more trial hiding techniques
            ' or don't use this property to use ALL techniques
            ' WARNING: trialRegistryPerUser is "Per User"; this means each user trial feature 
            ' is controlled that user's own registry hive.
            ' This means initiating a trial with one user does not initiate a trial for another user.
            ' trialHiddenFolder and trialSteganography are for "All Users"
            '.TrialHideType = ActiveLock3_6NET.IActiveLock.ALTrialHideTypes.trialHiddenFolder Or ActiveLock3_6NET.IActiveLock.ALTrialHideTypes.trialRegistryPerUser Or ActiveLock3_6NET.IActiveLock.ALTrialHideTypes.trialSteganography
            .TrialHideType = ActiveLock3_6NET.IActiveLock.ALTrialHideTypes.trialSteganography

            ' Use the following if you'd like to make the trial warning message persistent 
            ' until a license is registered.
            ' Expiration of the trial is not so clear to some users without any warnings.
            ' .trialWarningTemporary will show the trial expired warning only once.
            .TrialWarning = ActiveLock3_6NET.IActiveLock.ALTrialWarningTypes.trialWarningPersistent

            ' Set the Software code
            ' This is the same thing as VCode
            ' Run Alugen first and create a VCode and GCode 
            ' for the software name and version number you used above
            ' Then copy and use the VCode as the PUB_KEY here.
            ' It's up to you to encrypt it; just makes it more secure
            ' Enc encodes, Dec decodes the public key (VCode)
            ' Change Enc() and Dec(0 the way you want.
            '.SoftwareCode = Dec(PUB_KEY)
            .SoftwareCode = PUB_KEY

            ' uncomment the following when unmanaged Activelock3NET.dll is used
            '.LockType = ActiveLock3.ALLockTypes.lockNone

            ' Set the Hardware keys
            ' In order to pick the keys that you want to lock to in Alugen, use lockNone only
            ' Example: lockWindows Or lockComp
            ' You can combine any lockType(s) using OR as above
            ' WARNING: Short key licenses use the lockFingerprint by default
            ' WARNING: This has no effect for short key licenses
            .LockType = ActiveLock3_6NET.IActiveLock.ALLockTypes.lockNone
            '.LockType = ActiveLock3_6NET.IActiveLock.ALLockTypes.lockFingerprint
            '.LockType = ActiveLock3_6NET.IActiveLock.ALLockTypes.lockIP Or _
            'ActiveLock3_6NET.IActiveLock.ALLockTypes.lockComp

            ' If you want to lock to any keys explicitly, combine them using OR
            ' But you won't be able to uncheck/check any of them while in Alugen (too late at that point).
            '.LockType = _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockBIOS Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockComp Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockHD Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockHDFirmware Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockIP Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockMotherboard Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockWindows Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockMAC Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockExternalIP Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockFingerprint Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockSID Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockCPUID Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockBaseboardID Or _
            ' ActiveLock3_6NET.IActiveLock.ALLockTypes.lockVideoID

            ' USAGE OF .ALL (AUTO-REGISTER) FILES
            ' THESE FILES CARRY THE LICENSE (LIBERATION) KEY FOR AUTO REGISTRATION
            ' ALL FILES ARE NOT USED WITH SHORT-KEY LICENSES
            ' Set the .ALL file path if you're using an ALL file.
            ' .ALL is an auto registration file.
            ' You generate .ALL files via Alugen and then send to the users
            ' They put the .ALL file in the directory you specify below
            ' .ALL simply contains the license key
            ' WARNING: .ALL files are deleted after they are used.
            ' It is recommended that you use both SoftwareName and Version in the .ALL filename
            ' since multiple .ALL files might exist in the same directory
            ' If you don't want to use the software name and version number explicitly, use an .ALL
            ' filename that is specific to this application
            ' Be aware that Alugen will not accept creation of ALL files without
            ' the software name and version in the ALL filename.
            ' You can rename the ALL file afterwards, but that name should match the ALL filename used here.

            ' .ALL FILE STORAGE OPTION-1
            ' Try to use the simplest accessible solution for both XP and Vista such as C:\TEMP
            If My.Computer.FileSystem.DirectoryExists("c:\temp") = False Then
                My.Computer.FileSystem.CreateDirectory("c:\temp")
            End If
            strAutoRegisterKeyPath = String.Format("c:\temp\{0}{1}.all", .SoftwareName, .SoftwareVersion)

            ' .ALL FILE STORAGE OPTION-2
            ' The following (AppfilePath) is another option for both XP and Vista
            ' but you should be sure that the directory exists.
            ' Since this is also the folder where the LIC file resides, it's not recommended
            'If Directory.Exists(AppfilePath & "\" & .SoftwareName & .SoftwareVersion) = False Then
            '    MkDir(AppfilePath & "\" & .SoftwareName & .SoftwareVersion)
            'End If
            'strAutoRegisterKeyPath = AppfilePath & "\" & .SoftwareName & .SoftwareVersion & "\" & .SoftwareName & .SoftwareVersion & ".all"

            ' .ALL FILE STORAGE OPTION-3
            ' AppPath could be an option for XP, but not for Vista
            'If Directory.Exists(AppPath & "\" & .SoftwareName & .SoftwareVersion ) = False Then
            '    MkDir(AppPath & "\" & .SoftwareName & .SoftwareVersion)
            'End If
            'strAutoRegisterKeyPath = AppPath() & "\" & .SoftwareName & .SoftwareVersion & "\" & .SoftwareName & .SoftwareVersion & ".all"

            .AutoRegisterKeyPath = strAutoRegisterKeyPath

            If My.Computer.FileSystem.FileExists(strAutoRegisterKeyPath) Then boolAutoRegisterKeyPath = True

            ' Set if auto registration will be used.
            ' Auto registration uses the ALL file for license registration.
            .AutoRegister = ActiveLock3_6NET.IActiveLock.ALAutoRegisterTypes.alsEnableAutoRegistration

            ' Set the Time Server check for Clock Tampering
            ' This is optional but highly recommended.
            ' Although Activelock makes every effort to check if the system clock was tampered,
            ' checking a time server is the guaranteed way of knowing the correct UTC time/day.
            ' This feature might add some delay to your apps start-up time.
            .CheckTimeServerForClockTampering = ActiveLock3_6NET.IActiveLock.ALTimeServerTypes.alsDontCheckTimeServer       ' use alsCheckTimeServer to enforce time server checks for clock tampering check
            '.CheckTimeServerForClockTampering = ActiveLock3_6NET.IActiveLock.ALTimeServerTypes.alsCheckTimeServer

            ' Set the system files clock tampering check
            ' This feature might add some delay to your apps start-up time.
            .CheckSystemFilesForClockTampering = ActiveLock3_6NET.IActiveLock.ALSystemFilesTypes.alsDontCheckSystemFiles    ' use alsCheckSystemFiles to enforce system files scanning for clock tampering check
            '.CheckSystemFilesForClockTampering = ActiveLock3_6NET.IActiveLock.ALSystemFilesTypes.alsCheckSystemFiles

            ' Set the license file format; this could be encrypted or plain
            ' Even in a plain file format, certain keys and dates are still encrypted.
            .LicenseFileType = ActiveLock3_6NET.IActiveLock.ALLicenseFileTypes.alsLicenseFilePlain

            ' Initialize the keystore. We use a File keystore in this case.
            ' The other type alsRegistry is NOT supported.
            .KeyStoreType = ActiveLock3_6NET.IActiveLock.LicStoreType.alsFile
            ' uncomment the following when unmanaged Activelock3NET.dll is used
            'MyActiveLock.KeyStoreType = ActiveLock3.LicStoreType.alsFile

            ' The code below will put the LIC file inside the "...\All Users\Documents" folder
            ' You can hard code this path and put the LIC file anywhere you want
            ' But be careful with limited user accounts in Vista.
            ' It's recommended that you put this file in shared and accessible folders in Vista
            ' It is recommended that you use both SoftwareName and Version in the LIC filename
            ' since multiple LIC files might exist in the same directory
            ' If you don't want to use the software name and version number explicitly, use an LIC
            ' filename that is specific to this application
            If My.Computer.FileSystem.DirectoryExists("C:\temp") = False Then
                MkDir("C:\temp")
            End If
            strKeyStorePath = String.Format("C:\temp\{0}{1}.lic", .SoftwareName, .SoftwareVersion)
            ' AppPath could be an option for XP, but not so for Vista
            'If Directory.Exists(AppPath & "\" & .SoftwareName & .SoftwareVersion ) = False Then
            '    MkDir(AppPath & "\" & .SoftwareName & .SoftwareVersion)
            'End If
            'strKeyStorePath = AppPath() & "\" & .SoftwareName & .SoftwareVersion & "\" & .SoftwareName & .SoftwareVersion & ".lic"
            .KeyStorePath = strKeyStorePath

            ' Obtain the EventNotifier so that we can receive notifications from AL.
            ' Do Not Change This  - unless you know what this is for.
            ActiveLockEventSink = .EventNotifier

            ' Initialize Activelock 
            ' Use the following with ASP.NET applications
            ' MyActiveLock.Init(Application.StartupPath & "\bin")
            ' Use the following with VB.NET applications
            .Init(Application.StartupPath, strAutoRegisterKeyPath)
            If My.Computer.FileSystem.FileExists(strKeyStorePath) And boolAutoRegisterKeyPath = True And strAutoRegisterKeyPath <> "" Then
                ' This means, an ALL file existed and was used to create a LIC file
                ' Init() method successfully registered the ALL file
                ' and returned the license key
                ' You can process that key here to see if there is any abuse, etc.
                ' ie. whether the key was used before, etc.
            End If

        End With


        ' Check registration status
        ' Acquire() method does both trial and regular licensing
        ' If it generates an error, that means there NO trial, NO license
        ' If no error and returns a string, there's a trial but No license. Parse the string to display a trial message.
        ' If no error and no string returned, you've got a valid license.

        ' In case the Acquire method generates an error, so no license and no trial:
        ' If InStr(1, Err.Description, "No valid license") > 0 Or InStr(1, Err.Description, "license invalid") > 0 Then '-2147221503 & -2147221502
        Try
            MyActiveLock.Acquire(strMsg, strRemainingTrialDays, strRemainingTrialRuns, strTrialLength, strUsedDays, strExpirationDate, strRegisteredUser, strRegisteredLevel, strLicenseClass, strMaxCount, strLicenseFileType)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            GoTo Err
        End Try
        ' strMsg is to get the trial status
        ' All other parameters are Optional and you can actually get all of them
        ' using MyActivelock.Property usage, but keep in mind that 
        ' doing so will check the license every time making this a time consuming 
        ' way of reading those properties
        ' The fastest approach is to use the arguments from Acquire() method.
        If strMsg <> "" Then 'There's a trial
            ' Parse the returned string to display it on a form
            'Dim A() As String = strMsg.Split(vbCrLf)
            'txtRegStatus.Text = A(0).Trim
            'txtUsedDays.Text = A(1).Trim
            Trial(True)
            ' You can also get the RemainingTrialDays or RemainingTrialRuns directly by:
            'txtRemainingTrialDays.Text = MyActiveLock.RemainingTrialDays OR MyActiveLock.RemainingTrialRuns
            ' At this point RemainingTrialDays and RemainingTrialRuns properties are directly accessible
            ' Even if you don't want to show a trial form at this point, you still know the 
            ' trial status with one of these two properties (whichever is applicable).
            'FunctionalitiesEnabled = True


            ' ALTERNATIVE 2
            ' Show a splash form that shows two choices, register or try
            ' User must chosse one option for the form to close
            'MyActiveLock.RemainingTrialDays
            remainingDays = CInt(strRemainingTrialDays)
            remainingRuns = CInt(strRemainingTrialRuns)
            'MyActiveLock.TrialLength
            totalDays = CInt(strTrialLength)
            totalRuns = CInt(strTrialLength)
            Me.Refresh()
            Exit Sub
        Else
            MessageBox.Show("This is a fullversion software")
            Dim intRegisteredLevel As Integer = 0
            Select Case strRegisteredLevel
                Case "Abhi & Najin"
                    intRegisteredLevel = 1
                Case Else
                    MessageBox.Show(strRegisteredLevel)
            End Select
            EnableControls(intRegisteredLevel)
        End If

        ' You can retrieve the LockTypes set inside Alugen
        ' by accessing the UsedLockType property
        'For example, if only lockHDfirmware was used, this will return 256
        'MsgBox(MyActiveLock.UsedLockType)

        ' So far so good... 
        ' If you are here already, that means you have a valid license.
        ' Set the textboxes in your app accordingly.
        Reg_Status = "Registered"
        'MyActiveLock.UsedDays
        Used_Days = strUsedDays
        'MyActiveLock.ExpirationDate

        ' This will display the date in user's locale short date format
        Dim strSD As String = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern
        Dim strST As String = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern

        Expiration = Convert.ToDateTime(strExpirationDate).ToString(String.Format("{0} {1}", strSD, strST))
        If Expiration = "" Then
            Expiration = "Permanent" 'App has a permanent license
        End If

        Dim arrProdVer As String() = Split(strRegisteredUser, "&&&")
        'MyActiveLock.RegisteredUser ' Extract the software name and version
        User = arrProdVer(0)

        'MyActiveLock.RegisteredLevel
        RegisteredLevel = strRegisteredLevel

        ' Set Networked Licenses if applicable
        'MyActiveLock.LicenseClass
        'If strLicenseClass = "MultiUser" Then
        'txtNetworkedLicense.Text = "Networked"
        'Else
        'txtNetworkedLicense.Text = "Single User"
        'txtMaxCount.Visible = False
        'lblConcurrentUsers.Visible = False
        'End If
        ' This is for number of concurrent users count in a netwrok license
        'MyActiveLock.MaxCount
        'txtMaxCount.Text = strMaxCount

        ' Read the license file into a string to determine the license type
        ' You can read the LicenseType from the LIC file directly
        ' However, the LIC file should be in Plain format for this to work.
        ' MyActiveLock.LicenseFileType
        If strLicenseFileType = ActiveLock3_6NET.IActiveLock.ALLicenseFileTypes.alsLicenseFilePlain Then
            Dim strBuff As String
            Dim fNum As Short
            fNum = FreeFile()
            FileOpen(fNum, strKeyStorePath, OpenMode.Input)
            strBuff = InputString(1, LOF(1))
            FileClose(fNum)
            If Instring(strBuff, "LicenseType=3") Then
                LicenseType = "Time Limited"
            ElseIf Instring(strBuff, "LicenseType=1") Then
                LicenseType = "Periodic"
            ElseIf Instring(strBuff, "LicenseType=2") Then
                LicenseType = "Permanent"
            End If
        Else
            If strLicenseType = "3" Then
                LicenseType = "Time Limited"
            ElseIf strLicenseType = "1" Then
                LicenseType = "Periodic"
            ElseIf strLicenseType = "2" Then
                LicenseType = "Permanent"
            End If
        End If

Important:
        'For service controller
        ServiceController1.MachineName = My.Computer.Name

        'Code for taskbar buttons for Win 7
        Dim StopIcon, StartIcon As System.Drawing.Icon
        StopIcon = My.Resources.Resource1.shell32_240
        StartIcon = My.Resources.Resource1.shell32_246

        ApacheStart = New ThumbnailToolbarButton(StartIcon, "Start Apache")
        ApacheStop = New ThumbnailToolbarButton(StopIcon, "Stop Apache")
        MySQLStart = New ThumbnailToolbarButton(StartIcon, "Start MySQL")
        MySQLStop = New ThumbnailToolbarButton(StopIcon, "Stop MySQL")
        Dim array1() As Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolbarButton = {ApacheStart, ApacheStop, MySQLStart, MySQLStop}
        TaskbarManager.Instance.ThumbnailToolbars.AddButtons(Handle, array1)
        If String.IsNullOrEmpty(My.Settings.oAuthToken) Or String.IsNullOrEmpty(My.Settings.oAuthSecToken) Then
            T_LDetails = False
        Else
            T_LDetails = True
        End If
        Exit Sub
Err:
        MyActiveLock.ResetTrial()
        MyActiveLock.ResetTrial()
        GoTo Important
    End Sub

    'Code for taskbar bottons
    Private Sub ApacheStart_Click(ByVal sender As Object, ByVal e As ThumbnailButtonClickedEventArgs) Handles ApacheStart.Click
        StartApache_Click(Me.Handle, System.EventArgs.Empty)
    End Sub

    Private Sub FileSystemWatcher1_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
        MessageBox.Show("File " & e.Name & " Changed by the user " & My.User.Name)
    End Sub

    Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
        MessageBox.Show("File created: " & e.FullPath)
        'System.IO.File.Delete(e.FullPath)
    End Sub

    Dim x As Integer = 0
    Private Sub IRCToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IRCToolStripMenuItem.Click
        'Select Case (x)
        '    Case 0
        '        MessageBox.Show("We are currently working on this")
        '        x += 1
        '    Case 1
        '        MessageBox.Show("We already said we are working on this")
        '        x += 1
        '    Case 2
        '        MessageBox.Show("Try any other menu")
        '        x += 1
        '    Case 3
        '        MessageBox.Show("don't you have any other job")
        '        x += 1
        '    Case 4
        '        MessageBox.Show("We do not want you any more to use this program. Bye")
        '        End
        'End Select
        frmIRC.Show()
    End Sub

    Private Sub MediaPlayerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MediaPlayerToolStripMenuItem.Click
        frmPlayer.Show()
    End Sub

    Private Sub SaveClipboardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveClipboardToolStripMenuItem.Click
        frmClipboard.SaveClip()
    End Sub

    Private Sub ShowClipboardToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowClipboardToolStripMenuItem.Click
        frmClipboard.Show()
    End Sub

    Private Sub HelpToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem1.Click
        MessageBox.Show("Currently no help available")
    End Sub

    Public Sub Trial(ByVal status As Boolean)
        Select Case status
            Case True

        End Select
    End Sub

    Public Sub EnableControls(ByVal level As Integer)
        Select Case (level)
            Case 99     'Beta User

            Case 1      'Abhi & Najin
                EmailToolStripMenuItem.Enabled = True
            Case 2      'Sithu Special Beta user

            Case 3      'Users

            Case 9      'Hackers

            Case Else   'What ?
                MessageBox.Show("What level is this ?")
        End Select
        RegisterToolStripMenuItem.Enabled = False
    End Sub

    Public Function UserLevel(ByVal level As Integer) As String
        Select Case (level)
            Case 99     'Beta User
                UserLevel = "Beta User"
            Case 1      'Abhi & Najin
                UserLevel = "Special"
            Case 2      'Sithu Special Beta user
                UserLevel = "Special Beta user"
            Case 3      'Users
                UserLevel = "User"
            Case 9      'Hackers
                UserLevel = "Hackers"
            Case Else   'What ?
                UserLevel = "Unknown"
        End Select
    End Function

    Function Instring(ByVal x As String, ByVal ParamArray MyArray() As Object) As Boolean
        'Do ANY of a group of sub-strings appear in within the first string?
        'Case doesn't count and we don't care WHERE or WHICH
        Dim y As Object 'member of array that holds all arguments except the first
        For Each y In MyArray
            If InStr(1, x, y, 1) > 0 Then 'the "ones" make the comparison case-insensitive
                Instring = True
                Exit Function
            End If
        Next y
    End Function

    Private Sub RegisterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RegisterToolStripMenuItem.Click
        frmRegister.Show()
    End Sub

    Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        AboutBox.Show()
    End Sub

    Private Sub EmailToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmailToolStripMenuItem.Click
        If EmailToolStripMenuItem.Enabled = True Then
            frmMail.Show()
        End If

    End Sub

    Private Sub ScreenshotToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScreenshotToolStripMenuItem.Click
        frmScreenSHot.Show()
    End Sub

    Private Sub flowLayoutPanel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        fraTwitter.Left = Me.Width / 2 - fraTwitter.Width / 2 - 10
        fraTwitter.Top = Me.Height / 2 - fraTwitter.Height / 2 - 10
    End Sub

    Private Sub picLogo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picLogo.Click
        '
        'LoginForm.Show()
    End Sub

    Private Sub btnTweet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTweet.Click
        LoadTokens()
        If TextBox1.Text.Length > 0 Then
            If My.Settings.oYes = True Then
                Tweet2(TextBox1.Text)
            Else
                If (MessageBox.Show("Tokens not found. Click 'OK' to request for new token", "Token", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK) Then
                    GetTokens()
                    Tweet2(TextBox1.Text)
                End If
            End If
        End If
        GetAccountInfo()
    End Sub

    Private Sub GetAccountInfo()
        Dim twt As New TwitterAPI
        m_colFriends = New Collection
        m_colFollwer = New Collection
        Try
            twt.AuthenticateWith(ConsumerKey, ConsumerKeySecret, OAuthToken, OAuthTokenSecret)
            Dim twUser As TwitterUser = twt.AccountInformation
            picAvatar.ImageLocation = twUser.ProfileImageUrl
            lblfollowers.Text = "Followers: " & twUser.FollowersCount & ControlChars.NewLine & "Following: " & twUser.FriendsCount

            'Adding friends to the tvwFriends
            Me.tvwFriends.Nodes.Clear()
            Dim tnFriends As New TreeNode
            tnFriends.Text = "Friends"
            tvwFriends.Nodes.Add(tnFriends)
            For Each frnd As TwitterUser In twt.Friends
                Dim strFriend As String
                Dim tnFriend As New TreeNode
                strFriend = frnd.Name & "(" & frnd.ID & ")"
                tnFriend.Text = strFriend
                m_colFriends.Add(frnd, strFriend)
                'clbFriends.Items.Add(strFriend, False)
                tnFriend.StateImageIndex = 0
                tnFriend.SelectedImageIndex = 0
                tnFriends.Nodes.Add(tnFriend)
            Next

            Dim tnFollowers As New TreeNode
            tnFollowers.Text = "Following"
            tvwFollowers.Nodes.Add(tnFollowers)
            For Each frnd As TwitterUser In twt.Followers
                Dim strFollower As String
                Dim tnFollower As New TreeNode
                strFollower = frnd.Name & "(" & frnd.ID & ")"
                tnFollower.Text = strFollower
                m_colFollwer.Add(frnd, strFollower)
                'clbFriends.Items.Add(strFriend, False)
                tnFollowers.StateImageIndex = 0
                tnFollowers.SelectedImageIndex = 0
                tnFollowers.Nodes.Add(tnFollower)
            Next
        Catch ex As TwitterAPIException
            MessageBox.Show(ex.Message)
        End Try


        'UNDONE Need more work to do in this function
    End Sub

    Private Sub LoadTokens()

        OAuthTokenSecret = My.Settings.oAuthSecToken
        OAuthToken = My.Settings.oAuthToken
        T_LDetails = True
    End Sub

    Private Sub Tweet2(ByVal status As String)
        Dim tw As New TwitterAPI
        Try
            If T_LDetails = True Then
                tw.AuthenticateWith(ConsumerKey, ConsumerKeySecret, OAuthToken, OAuthTokenSecret)
                tw.Update(status)
            End If
        Catch ex As TwitterAPIException
            MessageBox.Show(ex.Message)
            MessageBox.Show(ex.Method)
            MessageBox.Show(ex.Response.Headers.Keys.ToString)
        End Try
    End Sub

    Private Sub GetTokens()
        Dim tw As New TwitterAPI
        Dim isPINValid As Boolean
        Try
            Dim url As String = tw.GetAuthorizationLink(ConsumerKey, ConsumerKeySecret)
            Process.Start(url)
            Dim oauth_PIN As String = InputBox("Enter the PIN:")
            If Not oauth_PIN = "" Then
                isPINValid = tw.ValidatePIN(oauth_PIN)
            End If
            If isPINValid Then
                OAuthToken = tw.OAuth_Token
                OAuthTokenSecret = tw.OAuth_TokenSecret
                My.Settings.oAuthSecToken = OAuthTokenSecret
                My.Settings.oAuthToken = OAuthToken
                My.Settings.oYes = True
                My.Settings.Save()
            End If
        Catch ex As TwitterAPIException
            MessageBox.Show("Error occured")
        End Try
    End Sub

    Private Sub YoutubeDownloaderToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles YoutubeDownloaderToolStripMenuItem.Click
        frmYoutube.Show()
    End Sub
End Class